<extend name="Public:template" />
<block name="page_body">
<!-- 购物车页面  -->
<header class="headerSub clearfix">
    <h2>确认订单</h2>
    <a href="{:U('Cart/index')}" class="backBtn leftBtn" >返回修改</a>
    <a href="{:U('Product/index')}" class="shoppingBtn rightBtn">继续购物</a>
</header>
<div class="content">
	<!-- 配送信息 -->
	<div class="listFormBox">
		<dl id="address" class="itemFormBox">
			<dt><span class="fl">配送地址</span><span class="fr" style="width:20px;">选择</span></dt>  
			<dd class="<notempty name='list'>none</notempty>">
				<span id="msg_info_add" class="errHolder" style="display:none;"></span>
				<form action="{:U('CustAddress/doAdd')}" name="form_add" id="form_add">
					<ul class="inputBox">
						<li><input  name="name" type="text" class="inputIconUser" placeholder="收货人" value="{$cust.name}"/> </li>
						<li><input  name="mobile" type="number" class="inputIconUser" placeholder="联系方式（手机或电话）" value="{$cust.mobile}" /></li>
						<li><input  name="address" type="text" class="inputIconPwd" placeholder="配送地址" /></li>
					</ul>
					<ul class="linkBtnBox">
						<li class="linkBtnBoxFull"><a href="#" class="linkBtn greenNorBg" onClick="doAdd()">保存</a></li>
					</ul>
				</form>
			</dd>
		</dl>
	</div>
	<!-- 商品清单 -->
	<div class="listContentBox">
		<h2>商品清单</h2>
		<volist name="cartItems" id="val">
		<dl id="product{$val.code}" class="itemContentBox">
			<dt></dt>  
			<dd class="">
				<p class="fl"></p>
				<p class="fr"><span class="now">¥{$val.price_vip}</span><span class="num">×{$val.num}</span></p>
			</dd>
		</dl>
		</volist>
	</div>
	
	<div class="cartBottomContainer">
	<!--统计信息-->
	<div class="cartTotal">
		<p class="alignR" id="suminfo">
			您购买了<span class="deepRed" >{$cartPrice.sum_kind_total}</span>种商品，总共<span class="deepRed" >{$cartPrice.sum_num_total}</span>件，总价<span class="deepRed" id="totalpricespan">¥{$cartPrice.sum_sale_total|number_format=###, 2,'.',''}</span>
    	</p>
    	<p class="alignR">
    		不含运费
    	</p>
    	
	</div>
	<if condition="$cartPrice.sum_kind_total gt 0">
		<!--操作按钮-->
		<div class="cartAction">
			<a href="#" class="leftBtn" onClick="doEmptyCart()"><i class="delBtn" ></i>返回修改</a>
			<a href="#" class="rightBtn" onClick="javascript:createOrder();">提交订单</a>
		</div>
	</if>

</div>
</block>
<block name="script_footer">
<script type="text/javascript">
$(document).ready(function(){
	
})
function searchProduct(){
	if($("#form_search").attr('action')!=''){
		$.ajax({
	        'url': $("#form_search").attr('action'),
	        'dataType': "json",
	        'data': $('#form_search').serialize(),
	        'success': function (data) {
	        	var list = data['list'];
	        	var page = data['page'];
	        	
	        	$.each(list,function(i,item){
	        		var productItemHtml = template.render('productTmpl', item);
	        		$(productItemHtml).appendTo("#productListView");
	        	});
	        	$("#form_search").attr('action',page['downPageUrl'])
	        	if(page['totalPages']==page['nowPage']){
	        		$(".morePageBtn").hide();
	        	}else{
	        		$(".morePageBtn").show();
	        	}
	        }
	    });
	}

}
function addToCart(code,num,edittype){
	//问题 直接在底部不加载数据了
	//document.location.href = "/cart/doadd.html?code="+code+"&num="+num+"&edittype="+edittype;
	var currNum = parseInt( $("#itemNum"+code).val());
	var leftNum = currNum+parseInt(num);
	if(currNum<=0||(edittype=='1' && leftNum<=0)){
		if(!confirm('确定将该商品从购物车中移除？')){
			return;
		}
	}
	$.ajax({
		'async': false, 
        'url': "/cart/doadd.html",
        'dataType': "json",
        'data': {'code':code,'num':num,'edittype':edittype},
        'success': function (data) {
        	if(data['error']=='0'){
	        	var cart_num = data['cart_num'];
	        	var item_num = data['item_num'];
	        	$("#cartNum").html(cart_num);
	        	$("#itemNum"+code).val(item_num);
	        	if(item_num<=0){
	        		$("#item"+code).remove();
	        	}
	        	if(cart_num<=0){
	        		$(".cartAction").hide();
	        	}
        	}else{
        		alert(data['message']);
        	}
        }
    });
}
function doEmptyCart(){
	if(confirm('确定清空购物车?')){
		document.location.href="/Cart/doEmpty.html";
	}
}
</script>
</block>